package com.xinqi.modules.prepare.notice.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareNoticeData;
import com.xinqi.modules.prepare.notice.domain.PrepareNoticeEntity;
import com.xinqi.modules.prepare.notice.dto.req.PrepareNoticeCreateDTO;
import com.xinqi.modules.prepare.notice.dto.req.PrepareNoticeUpdateDTO;
import com.xinqi.modules.prepare.notice.dto.rsp.PrepareNoticeResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区公告转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareNoticeConvert {
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareNoticeEntity create(PrepareNoticeCreateDTO s);

    public abstract PrepareNoticeCreateDTO create(PrepareNoticeData s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareNoticeEntity update(PrepareNoticeUpdateDTO s, @MappingTarget PrepareNoticeEntity t);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareNoticeEntity update(PrepareNoticeUpdateDTO s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract PrepareNoticeResultDTO convert(PrepareNoticeEntity s);

    public abstract PrepareNoticeData convert(PrepareNoticeResultDTO s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareNoticeEntity copy(PrepareNoticeEntity s, @MappingTarget PrepareNoticeEntity t);
}
